#include <iostream>
using namespace std;

/**
 * 小黑当站长2，用数组实现单链表
 */
int main() {
    int train[5] = {0, 10, 20, 30, 40};
    int next[5] = {-1, -1, -1, -1, -1};
    int head;
    cin>>head;
    int cur=head;
    for(int i=1;i<=3;i++){
        int ne;
        cin >> ne;
        next[cur] = ne;
        cur  = ne;
    }

    while(head != -1) {
        cout << train[head] << " ";
        head = next[head];
    }
    return 0;
}